Radar Host Communication library  2020.08.13
COMPort.h File Reference

This file defines the API to access a serial communication port. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define IFX_RADAR_VID   "058B"
 
#define IFX_RADAR_PID   "0058"
 
#define IFX_RADAR_FF_PID   "0250"
 

Typedefs

typedef struct com_s com_t
 

Functions

uint32_t com_get_port_list (char *port_list, size_t buffer_size)
 This function returns a list of available COM ports. More...
 
com_t * com_open (const char *port_name)
 This functions opens the specified COM port. More...
 
void com_close (com_t *com_port)
 This function closes the specified COM port. More...
 
size_t com_send_data (com_t *com_port, const void *data, size_t num_bytes)
 This function sends data through an open COM port. More...
 
size_t com_get_data (com_t *com_port, void *data, size_t num_requested_bytes)
 This function reads data from an open COM port. More...
 
void com_set_timeout (com_t *com_port, uint32_t timeout_period_ms)
 This function changes the timeout period of an open COM port. More...
 

Detailed Description

This file defines the API to access a serial communication port.

This interface is an abstraction of a serial communication port. The interface provides basic operations open, close, read and write. Additionally it allows to get a list of available ports.

Even though the name is 'COMPort', the actual communication may use a different type of connection (COM, USB, SPI, etc.). The implementation is platform specific and will look differently for each combination of platform and connection type.

Definition in file COMPort.h.

Macro Definition Documentation

◆ IFX_RADAR_FF_PID

#define IFX_RADAR_FF_PID   "0250"

Definition at line 49 of file COMPort.h.

◆ IFX_RADAR_PID

#define IFX_RADAR_PID   "0058"

Definition at line 46 of file COMPort.h.

◆ IFX_RADAR_VID

#define IFX_RADAR_VID   "058B"

Definition at line 45 of file COMPort.h.

Typedef Documentation

◆ com_t

typedef struct com_s com_t

Definition at line 51 of file COMPort.h.

Function Documentation

◆ com_close()

void com_close ( com_t *  com_port)

This function closes the specified COM port.

The function expects a handle to an open COM port that have been returned by com_open.

Parameters
[in]com_portThe COM port that should be closed.

◆ com_get_data()

size_t com_get_data ( com_t *  com_port,
void *  data,
size_t  num_requested_bytes 
)

This function reads data from an open COM port.

The function tries to read the specified number of bytes from an open COM port and stores them in the provided buffer. The function waits for the data, but returns after an internally defined timeout period and returns the number of received bytes.

The function expects a handle to an open COM port that have been returned by com_open.

Parameters
[in]com_portThe open COM port.
[out]dataA pointer to the buffer where the received data will be stored.
[in]num_requested_bytesThe number of bytes that should be read from the COM port.
Returns
The function returns the number of bytes that actually have been received. This number may be smaller than uNumRequestedBytes.

◆ com_get_port_list()

uint32_t com_get_port_list ( char *  port_list,
size_t  buffer_size 
)

This function returns a list of available COM ports.

The port list is compiled into a zero terminated string, where all available ports are separated by a semicolon (';'). The string buffer to hold the port list must be provided by the caller. If the buffer is not sufficient to hold the names of all available ports, it is filled with as much complete port names as possible. Port names will not be truncated.

The function will return the number of available COM ports regardless of the number of port names that have been written to the buffer. The caller can count the number of names in the string buffer and compare with the returned number to check if it is sensible to call this function again with a bigger string buffer.

Parameters
[out]port_listA pointer to the string buffer where the port names will be written to.
[in]buffer_sizeThe size of the string buffer in bytes.
Returns
The function returns the number of available COM ports.

◆ com_open()

com_t* com_open ( const char *  port_name)

This functions opens the specified COM port.

The name of the COM port must be provided as zero terminated string. It is recommended to call com_get_port_list to find the available COM ports and pass one of the returned port names to the open function.

Parameters
[in]port_nameA zero terminated string containing the name of the COM port
Returns
If the function succeeds, the opened COM port object is returned. If the COM port could not be opened, NULL is returned.

◆ com_send_data()

size_t com_send_data ( com_t *  com_port,
const void *  data,
size_t  num_bytes 
)

This function sends data through an open COM port.

The function transmits each byte from the provided buffer through the specified COM port and returns after the last byte has been sent.

The function expects a handle to an open COM port that have been returned by com_open.

Parameters
[in]com_portThe open COM port.
[in]dataA pointer to the buffer containing the data to be sent.
[in]num_bytesThe number of bytes in pBuffer.

◆ com_set_timeout()

void com_set_timeout ( com_t *  com_port,
uint32_t  timeout_period_ms 
)

This function changes the timeout period of an open COM port.

This function changes the timeout period that will be used when data is read through com_get_data. That function will wait until timeout period is elapsed before returning, if not enough data is received.

The function expects a handle to an open COM port that have been returned by com_open.

Parameters
[in]com_portThe open COM port.
[in]timeout_period_msThe new timeout period in milli seconds.